package com.example.firstproject.controller;

import com.example.firstproject.common.WrapMapper;
import com.example.firstproject.common.Wrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author: lihua
 * @Date: 2024/4/25 14:20
 * @Version: v1.0.0
 * @Description:
 **/
@Slf4j
@RestController
@RequestMapping("/file")
public class FileController {

    private String filePath = "/Users/lihua/workspace/java/FirstProject/";
    @RequestMapping(value = "/upload",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> fileUpload(@RequestParam MultipartFile [] file){
        for (MultipartFile file1 : file){
            String name = file1.getOriginalFilename();
            try {
                file1.transferTo(new File(filePath + name));
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        Map<String,Object> retData = new HashMap<>();
        retData.put("massage","test");
        return retData;
    }

}
